typeof dnn==="undefined"&&(dnn={});if(typeof dnn.log==="undefined")dnn.log=function(){for(var a in arguments)typeof console!=="undefined"&&typeof console.log!=="undefined"&&console.log(arguments[a])};
function Gallery(a){var b={rowId:0,index:1,pageSize:10,orderBy:"",orderDir:"",thenBy:"",thenDir:"asc",animationSpeed:"slow",pageIdx:1,pageSze:10,smoothScrolling:!0,extensions:{},action:"filter",extensionFilter:"module",tagFilter:"",tagFilterName:"",ownerFilter:"",tags:{},loadTags:!0,pagedExtensions:{},protocol:"https:"==location.protocol?"https://":"http://",host:"catalog.dotnetnuke.com",ServiceRoot:"/AppGalleryService.svc",DataBaseVersion:"06.00.00",ExtensionServiceName:"/Extensions",
TagsServiceName:"/Tags",TagCloudServiceName:"/GetTagCloudData",CatalogServiceName:"/Catalogs",ExtensionSearchName:"/SearchExtensions",extensionDetailDialog:$("#extensionDetail").dialog(this.DefaultDialogOptions),loading:$("#loading"),NameTextASC:"Name: A-Z",NameTextDESC:"Name: Z-A",PriceTextASC:"Price: High to Low",PriceTextDESC:"Price: Low to High",TagCount:50,CacheTimeoutMinutes:1440,searchFilters:$("#searchFilters"),tagLabel:"Tag",searchLabel:"Search",vendorLabel:"Vendor",typeLabel:"Type",noneLabel:"None",
orderLabel:"Order:",errorLabel:"Error...",loadingLabel:"Loading...",BaseDownLoadUrl:"",searchText:""};a&&$.extend(b,a);for(var c in b)b.hasOwnProperty(c)&&(this[c]=b[c]);this.extensionList=$("#extensionList");this.smoothScrolling&&(new Scroller(100,!1,function(){_gallery.index++;_gallery.action="page";_gallery.Search()})).watch();this.ExtensionsUrl=this.getServiceUrl(this.ExtensionServiceName);this.TagCloudUrl=this.getServiceUrl(this.TagCloudServiceName);this.TagsUrl=this.getServiceUrl(this.TagsServiceName);
this.CatalogsUrl=this.getServiceUrl(this.CatalogServiceName);this.SearchUrl=this.getServiceUrl(this.ExtensionSearchName);this.Cache=new Cache("_Gallery_",this.CacheTimeoutMinutes);$("#typeDDL").change(function(a){_gallery.FilterGallery(a||window.event,this);return!1});$("#tag-list").click(function(a){a=a||window.event;_gallery.TagFilterGallery(a,this);return!1});$("#search-reset").click(function(){$("#searchText").val("");_gallery.tagFilter="";_gallery.tagFilterName="";_gallery.ownerFilter="";_gallery.orderBy=
"ExtensionName";_gallery.orderDir="asc";_gallery.extensionFilter="module";$("#typeDDL").val("module");_gallery.SearchGallery("");_gallery.getTags();return!1});$("#searchText").change(function(){_gallery.SearchGallery($("#searchText").val());return!1});$(document).keydown(function(a){a=a||window.event;a.which==13&&(window.stop(),a.stopPropagation(),a.preventDefault(),_gallery.SearchGallery($("#searchText").val()))});$("#searchText").keyup(function(a){a=a||window.event;a.which==27&&$("#search-reset").click();
return!1});$("#search-go").click(function(){_gallery.SearchGallery($("#searchText").val());return!1});$("#NameSorter").click(function(){_gallery.SortExtensions("ExtensionName");return!1});$("#PriceSorter").click(function(){_gallery.SortExtensions("Price");return!1})}Gallery.prototype.resolveImage=function(a){var b=a;a.indexOf("~")==0&&(b=this.siteRoot+a.substr(2));return b};
Gallery.prototype.showLoading=function(){this.reposition();this.loading.css("background-color","");this.loading.text(this.loadingLabel);this.loading.show()};Gallery.prototype.hideLoading=function(){this.loading.hide()};Gallery.prototype.errorLoading=function(a){this.loading.css("background-color","red");this.loading.text(this.errorText);this.loading.attr("title",a[0].statusText);this.loading.attr("alt",a[0].statusText)};
Gallery.prototype.reposition=function(){var a=$(window);this.loading.css("top",a.scrollTop());this.loading.css("left",a.width()/2-this.loading.width()/2)};
Gallery.prototype.SortExtensions=function(a,b){this.index=1;this.action="sort";b?(this.orderBy=a,this.orderDir=b):this.ToggleSort(a);if(this.orderBy&&this.orderDir){var c=$("#NameSorter"),e=$("#PriceSorter");this.orderBy=="ExtensionName"?this.orderDir=="asc"?c.text(this.NameTextDESC):c.text(this.NameTextASC):this.orderBy=="Price"&&(this.orderDir=="asc"?e.text(this.PriceTextDESC):e.text(this.PriceTextASC))}return this.Search()};
Gallery.prototype.ToggleSort=function(a){if(this.orderBy!==a)this.thenBy=this.orderBy,this.thenDir=this.orderDir,this.orderBy=a,this.orderDir="";this.orderDir=!this.orderDir||this.orderDir===""||this.orderDir=="desc"?"asc":"desc"};Gallery.prototype.SearchGallery=function(a){this.action="search";this.searchText=a?a:"";this.index=1;return this.Search()};Gallery.prototype.OwnerFilterGallery=function(a){this.action="filter";if(a)this.ownerFilter=a;this.index=1;return this.Search()};
Gallery.prototype.TagFilterGallery=function(a){var a=a||window.event,a=$(a.srcElement||a.target),b=a.attr("tagId");this.action="filter";if(b)this.tagFilter=b,this.tagFilterName=a.html();this.index=1;return this.Search()};Gallery.prototype.FilterGallery=function(a){a=$(a.srcElement||a.target).attr("value");this.action="filter";if(a)this.extensionFilter=a;this.getTags();this.index=1;return this.Search()};Gallery.prototype.Search=function(){this.getExtensions();return this};
Gallery.prototype.getServiceUrl=function(a){return this.protocol+this.host+this.ServiceRoot+a};
Gallery.prototype.getExtensions=function(){var a=this.tagLabel+" ",b="",c="",e=(this.index-1)*this.pageSize,d=e>0;this.tagFilter&&this.tagFilter!==""?(b=this.TagsUrl+"("+this.tagFilter+")/ExtensionTags/?$expand=Extension",c="Extension/",a+=this.tagFilterName,d=!0):(b=this.ExtensionsUrl+"?",a+=this.noneLabel);a=a+", "+this.searchLabel+" ";b+="&$inlinecount=allpages&$skip="+e+"&$top="+this.pageSize;this.searchText&&this.searchText!==""?(b=b+"&$filter="+encodeURIComponent("(substringof('"+this.searchText+
"', "+c+"ExtensionName) eq true or substringof('"+this.searchText+"', "+c+"Description) eq true or substringof('"+this.searchText+"', "+c+"Title) eq true)"),a+=this.searchText,d=!0):a+=this.noneLabel;a=a+", "+this.typeLabel+" ";this.extensionFilter&&this.extensionFilter!==""&&this.extensionFilter!=="all"?(this.extensionFilter=="module"?a+="Module":(d=!0,a+="Skin"),b+=b.indexOf("$filter")<0?"&$filter=":"and ",b=b+""+c+"ExtensionType eq '"+this.extensionFilter+"'"):(d=!0,a+="All");a=a+", "+this.vendorLabel+
" ";this.ownerFilter&&this.ownerFilter!==""?(a+=this.ownerFilter,b+=b.indexOf("$filter")<0?"&$filter=":"and ",b+=encodeURIComponent(""+c+"OwnerName eq '"+this.ownerFilter+"'"),d=!0):a+=this.noneLabel;this.DataBaseVersion&&this.DataBaseVersion!==""?(b+=b.indexOf("$filter")<0?"&$filter=":"and ",b+=encodeURIComponent(""+c+"MinDnnVersion lt '"+this.DataBaseVersion+"'")):a+=this.noneLabel;a=a+", "+this.orderLabel+" ";this.orderBy!==""?(b=b+"&$orderby="+encodeURIComponent(c+""+this.orderBy+" "+this.orderDir),
this.orderBy=="ExtensionName"?this.orderDir=="asc"?a+=this.NameTextASC:(d=!0,a+=this.NameTextDESC):(d=!0,a+=this.orderDir=="asc"?this.PriceTextASC:this.PriceTextDESC)):a+=this.noneLabel;this.thenBy!==""&&(b=b+","+encodeURIComponent(c+""+this.thenBy+" "+this.thenDir),this.thenBy=="ExtensionName"?this.thenDir=="asc"?a=a+", "+this.NameTextASC:(d=!0,a=a+", "+this.NameTextDESC):(d=!0,a=this.thenDir=="asc"?a+", "+this.PriceTextASC:a+", "+this.PriceTextDESC));this.searchFilters.text(a);b+="&$format=json";
if(!_gallery.extensions.d||!d)if(a=this.Cache.getItem("__FIRSTLOAD")){Gallery.gotExtensions(a);return}dnn.log(b);this.showLoading();this.eXHR=this.getXHR(b,"gotExtensions")};
Gallery.gotExtensions=function(a){var b=_gallery;if(a&&a.d&&a.d.results)for(var c in a.d.results){var e=a.d.results[c];typeof e.Extension!="undefined"?e.Extension.Catalog=b.getCatalog(e.Extension.CatalogID):e.Catalog=b.getCatalog(e.CatalogID)}_gallery.Cache.hasItem("__FIRSTLOAD")||_gallery.Cache.setItem("__FIRSTLOAD",a);if(a.d.results.length>0&&typeof a.d.results[0].Extension!="undefined")for(var d in a.d.results)for(c in a.d.results[d].Extension)a.d.results[d].Extension.hasOwnProperty(c)&&(a.d.results[d][c]=
a.d.results[d].Extension[c]);_gallery.pagedExtensions=a.d.results;_gallery.extensions&&_gallery.extensions.d&&_gallery.extensions.d.results&&!(_gallery.action=="search"||_gallery.action=="filter"||_gallery.action=="sort")?_gallery.extensions.d.results=_gallery.extensions.d.results.concat(a.d.results):_gallery.extensions=a;_gallery.showExtensions(function(){});_gallery.hideLoading()};
Gallery.prototype.showExtensions=function(a){this.pageCount=Math.ceil(this.extensions.d.__count/this.pageSize);this.smoothScrolling||this.extensionList.empty();(this.action=="search"||this.action=="filter"||this.action=="sort")&&this.extensionList.empty();this.pagedExtensions.length>0&&$("#eTmpl").tmpl(this.pagedExtensions).appendTo(this.extensionList).fadeIn(this.animationSpeed);this.pagedExtensions=[];a&&a(this)};
Gallery.prototype.getExtensionById=function(a){if(this.extensions&&this.extensions.d)for(var b=this.extensions.d.results,c=b.length;c--;)if(b[c].ExtensionID==a)return b[c]};
Gallery.prototype.FormatCurrency=function(a){a=a.toString().replace(/\$|\,/g,"");isNaN(a)&&(a="0");sign=a==(a=Math.abs(a));a=Math.floor(a*100+0.50000000001);cents=a%100;a=Math.floor(a/100).toString();cents<10&&(cents="0"+cents);for(var b=0;b<Math.floor((a.length-(1+b))/3);b++)a=a.substring(0,a.length-(4*b+3))+","+a.substring(a.length-(4*b+3));return(sign?"":"-")+"$"+a+"."+cents};Gallery.prototype.DefaultDialogOptions={modal:!0,autoOpen:!1,width:800,height:600,resizable:!0,closeOnEscape:!0};
Gallery.prototype.getDownloadUrl=function(a){return this.BaseDownLoadUrl.replace(escape("{{ExtensionID}}"),a)};Gallery.prototype.ShowDetails=function(a){if(a=this.getExtensionById(a)){var b=$("#extensionDetailInner");b.empty();$("#extDetailTmpl").tmpl(a).appendTo(b);$("#extensionDetail-tabs").tabs();this.extensionDetailDialog.dialog({title:a.ExtensionName});this.extensionDetailDialog.dialog("open")}return!1};
Gallery.prototype.getCatalog=function(a){for(var b in this.cats.d)if(this.cats.d[b].CatalogID==a)return this.cats.d[b];return null};Gallery.gotCatalogs=function(a){_gallery.cats=a;_gallery.Cache.hasItem("catalogs")||_gallery.Cache.setItem("catalogs",a)};
Gallery.prototype.getCatalogs=function(a){var b=this.CatalogsUrl;b+="?$format=json";var c=this.Cache.getItem("catalogs");c?(Gallery.gotCatalogs(c),typeof a!="undefined"&&$.isFunction(a)&&a()):(this.showLoading(),dnn.log(b),this.tagXHR=this.getXHR(b,"gotCatalogs"),typeof a!="undefined"&&$.isFunction(a)&&this.tagXHR.complete(function(){a()}))};
Gallery.prototype.getTags=function(){var a=this.TagCloudUrl+"?Tagcount="+(this.TagCount?this.TagCount:15),a=a+"&ExtensionType='"+this.extensionFilter+"'";a+="&MinDnnVersion=''";a+="&$format=json";var b=this.Cache.getItem("tags_"+this.extensionFilter);b?(_gallery.tags=b.sort(Gallery.tagSort),_gallery.loadTags=!1,_gallery.showTags()):(this.showLoading(),dnn.log(a),this.tagXHR=this.getXHR(a,"gotTags"))};Gallery.gotTags=function(a){_gallery.resolveTags(a)};
Gallery.prototype.resolveTags=function(a){for(var b=[],c=0,e=0,d,e=a.d.length-1;e>=0;e--)if(d=a.d[e],Gallery.validTag(d)){if(d.TagCount>c)c=d.TagCount;b.push(d)}for(e in b)if(d=b[e],d.fontSize=(d.TagCount/c*250).toFixed(2),d.fontSize<75)d.fontSize=75;this.loadTags=!1;this.tags=b.sort(Gallery.tagSort);this.Cache.setItem("tags_"+this.extensionFilter,_gallery.tags);this.showTags();this.hideLoading()};
Gallery.tagSort=function(a,b){var c=a.tagName.toLowerCase(),e=b.tagName.toLowerCase();if(c<e)return-1;if(c>e)return 1;return 0};Gallery.prototype.showTags=function(a){var b=$("#tag-list"),c=$("#tag-tmpl");b.empty();this.tags?(c.tmpl(this.tags).appendTo(b),b.fadeIn(this.animationSpeed)):b.fadeOut(this.animationSpeed);a&&a(this)};Gallery.validTag=function(a){return a&&a.tagName&&a.tagName.indexOf("DotNetNuke")<0&&a.TagCount>0};
Gallery.prototype.getXHR=function(a,b){return $.getJSON(a+"&$callback=?",Gallery[b]).error(function(){_gallery.errorLoading(arguments)})};
Cache=function(a,b,c,e){this.StorageType=c||"localStorage";if(this.StorageType!="localStorage"||this.StorageType!="sessionStorage"||this.StorageType!="globalStorage")this.StorageType="localStorage";this.Scope=a||"";this.TimeoutInMinutes=b;this.expireCallback=e;this.loadStore();Cache.isEnabled=typeof this.store!="undefined"&&typeof JSON!="undefined"&&(typeof this.TimeoutInMinutes=="undefined"||typeof this.TimeoutInMinutes!="undefined"&&this.TimeoutInMinutes>0);if(Cache.isEnabled&&typeof this.TimeoutInMinutes!=
"undefined")$(document).ready(function(){Cache.ClearInterval()});this.cacheExpire=window.setInterval(Cache.ClearInterval,b*6E4,this);return this};Cache.isEnabled=!1;Cache.prototype.loadStore=function(){switch(this.StorageType){case "globalStorage":try{if(window.globalStorage)this.store=window.globalStorage[window.location.hostname]}catch(a){}break;case "sessionStorage":try{if(window.sessionStorage)this.store=window.sessionStorage}catch(b){}break;default:try{if(window.localStorage)this.store=window.localStorage}catch(c){}}return this};
Cache.ClearInterval=function(a){if(typeof a==="undefined")a=_gallery.Cache;if(typeof a.TimeoutInMinutes!="undefined")if(a.hasItem(a.Scope+"_expire")){var b=a.getItem(a.Scope+"_expire");(new Date-Date.parse(b))/6E4>a.TimeoutInMinutes&&(a.EmptyCache(),typeof a.expireCallback!="undefined"&&a.expireCallback(i))}else a.setItem(a.Scope+"_expire",new Date);return this};
Cache.prototype.EmptyCache=function(){var a,b;try{for(b in this.store)this.store.hasOwnProperty(b)&&b.substr(0,this.Scope.length)==this.Scope&&this.store.removeItem(b)}catch(c){try{for(x=a=this.store.length-1;x>=0;x--)b=this.store[x],this.store.hasOwnProperty(b)&&b.substr(0,this.Scope.length)==this.Scope&&this.store.removeItem(b)}catch(e){this.store.clear()}}return this};
Cache.prototype.hasItem=function(a){if(Cache.isEnabled)return(a=this.store.getItem(this.Scope+a))&&a!==null&&typeof a!=="undefined";return!1};Cache.prototype.getItem=function(a){var b,c;if(Cache.isEnabled){b=this.store.getItem(this.Scope+a);try{c=$.parseJSON(b)}catch(e){this.store.removeItem(this.Scope+a)}}return c};Cache.prototype.setItem=function(a,b){Cache.isEnabled&&this.store.setItem(this.Scope+a,JSON.stringify(b));return this};
Scroller=function(a,b,c){this.page=1;this.maxPage=a?a:100;this.loadScroll=typeof b!="undefined"?b:!1;this.scrollcallback=c;this.loadScroll&&this.loadScroller()};Scroller.prototype.handleScroll=function(){this.page++;this.scrollcallback&&this.scrollcallback(this);this.page>=this.maxPage&&this.unwatch()};Scroller.prototype.loadScroller=function(){for(var a=!0;a;)(a=$(window).scrollTop()>=$(document).height()-$(window).height())&&this.handleScroll(),this.page>=this.maxPage&&(a=!1)};
Scroller.prototype.watch=function(){window.Scroller=this;var a=$(window);a.scroll||(a=$(document));a.scroll(function(){var a=window.Scroller;$(window).scrollTop()>=$(document).height()-$(window).height()&&a.handleScroll()})};Scroller.prototype.unwatch=function(){$(document).unbind("scroll")};Math.random.range=function(a,b,c){if(typeof c!=="undefined"||!c)a-=1;b+=1;return Math.floor(b+(1+a-b)*Math.random())};
